package hander

import (
	"github.com/gin-gonic/gin"
	"good/api/reponse"
	"good/api/request"
	"good/internal/dao"
	"good/internal/models"
	"gorm.io/gorm"
)

func Upload(c *gin.Context) {
	req := request.Upload{}
	if err := c.ShouldBind(&req); err != nil {
		reponse.ErrorRequest(c, "绑定失败")
		return
	}
	user := models.User{
		Model:        gorm.Model{ID: uint(req.Id)},
		Phone:        req.Phone,
		NickName:     req.NickName,
		AvatarUrl:    req.AvatarUrl,
		Region:       req.Region,
		Introduction: req.Introduction,
	}
	if err := dao.Upload(&user, req.Id); err != nil {
		reponse.ErrorRequest(c, "更新失败")
		return
	}
	reponse.SuccessRequest(c, "更新成功", req.Id)
}
